package pers.zb.cloud.web.upms.vo;

import lombok.Data;

import java.io.Serializable;
import java.util.List;

@Data
public class Page<T> implements Serializable {

    private List<T> list;
    private int pageNumber; //当前的页码
    private int pageSize; //每页数据条数
    private int totalPage; //总页码
    private int totalRow; //总数据量

    private String sort;//排序的字段名
    private String order;//desc 或者 asc

    public Page(List<T> list, Page pageParam , int totalRow) {
        this.list = list;
        this.pageNumber = pageParam.getPageNumber();
        this.pageSize = pageParam.getPageSize();
        //this.totalPage = pageParam.getTotalPage();
        this.totalRow = totalRow;
    }

    public Page() {
    }

    public boolean isFirstPage() {
        return this.pageNumber == 1;
    }

    public boolean isLastPage() {
        return this.pageNumber >= this.totalPage;
    }

    public int getTotalPage() {
        int totalPage = totalRow / pageSize;
        if (totalRow % pageSize != 0) {
            ++totalPage;
        }
        return totalPage;
    }
}